;var module = angular.module('CtrlsContent');
module.controller('ListSelectCtrl',['$scope','$state','api_other','$stateParams',function($scope,$state,api_other,$stateParams){
	$scope.listModel = {
		model:[],
		get:function(obj){
			var self = this;
			var promise = api_other.testList(obj);
			promise.success(function(data){
				if(data.returnCode == 0){
					self.model = data.returnData
				}
			});
			return promise;
		}
	};
	$scope.event = {
		init:function(){
			this.typeAndStatusInit();
			this.getList();
		},
		changeType:function(type){
			$scope.eleStatus.type = type;
			this.getList();
		},
		typeAndStatusInit:function(){
			if($scope.eleStatus.param == 1){
				$scope.eleStatus.type = 1;
				$scope.eleStatus.status = 1;
			}
			if($scope.eleStatus.param == 2){
				$scope.eleStatus.type = 2;
				$scope.eleStatus.status = 1;
			}
			if($scope.eleStatus.param == 3){
				$scope.eleStatus.type = 1;
				$scope.eleStatus.status = 2;
			}
			if($scope.eleStatus.param == 4){
				$scope.eleStatus.type = 1;
				$scope.eleStatus.status = 3;
			}
		},
		getList:function(item){

			if(item){
				if(item.num == 0){
					alert('没有题可以做，请重新选择');
					return ;
				}
				var obj = {
					parent_id:item.id,
					userId:localStorage.bls_userId,
					type:$scope.eleStatus.type,
					status:$scope.eleStatus.status
				};
				$scope.eleStatus.title = item.catname;
			}else{

				var obj = {
					parent_id:localStorage.catId,
					userId:localStorage.bls_userId,
					type:$scope.eleStatus.type,
					status:$scope.eleStatus.status
				};
				
			}
			
			var promise = $scope.listModel.get(obj);
			promise.success(function(data){
				if(item && item.status == 1){
					localStorage.zhangjieCatId = item.id;
					$state.go('zhangjieContent',{param:$scope.eleStatus.param,type:$scope.eleStatus.type,totals:item.num});
				}
			});
		}
	};
	$scope.eleStatus = {
		title:'选择科目',
		param:$stateParams.type,
		type:1,
		status:1
	};
	$scope.event.init();
	
}]);